<template>
    <div v-if="visible" class="loading-box">
        <div class="loading-spinner"></div>
    </div>
</template>
<script lang="ts">
import { defineComponent, ref } from 'vue';
export default defineComponent({
    name: 'Loading',
    setup() {
        // 控制组件的状态
        const visible = ref(false);

        // 显示组件
        const showLoading = () => {
            visible.value = true;
        };
        // 隐藏组件
        const hideLoading = () => {
            visible.value = false;
        };

        return { visible, showLoading, hideLoading };
    }
});
</script>

<style scoped>
.loading-box {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    background: rgb(0 0 0 / 50%);
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-radius: 50%;
    border-top: 4px solid #3498db;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}
</style>
